{template 'common/header'}
<link rel="stylesheet" type="text/css" href="../addons/{php echo $_GPC['m']}/resource/css/style.css" />
<link rel="stylesheet" type="text/css" href="../addons/{php echo $_GPC['m']}/resource/swal/dist/sweetalert2.min.css" />
<link rel="stylesheet" type="text/css" href="../addons/{php echo $_GPC['m']}/resource/bootstrap-select/bootstrap-select.min.css" />
<style>

</style>
<div class="form-group" style="display: none;">
    <label  class="col-sm-2 control-label">首页图片(375*250)</label>
    <div class="col-sm-8">
        {php echo tpl_form_field_image('wwww');}
    </div>
</div>
<div class="panel panel-default">
    <div class="panel-heading">
        <h3 class="panel-title">
            砍价>编辑
        </h3>
    </div>
    <div class="panel-body">
        <form id="sign-form" class="form-horizontal" role="form" method="post" name="submit" style="padding: 20px 0;">
            <div class="form-group">
                <label class="col-sm-2 control-label">课程</label>
                <div class="col-sm-8">
                    <select id="pid" class="selectpicker show-tick form-control bs-select-hidden" data-live-search="true" name="pid" style="width: 50%;">
                        <option value="0" hassubinfo="true">请选择课程</option>
                        {loop $class $index $vo}
                        <option value="{$vo['id']}" {if $vo['id']==$list['pid']}selected{/if}>{$vo['name']}</option>
                        {/loop}
                    </select>
                    <input type="hidden" name="id" value="{$list['id']}">
                    <input type="hidden" name="link">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">标识</label>
                <div class="col-sm-8">
                    <input type="text" class="form-control"  name="mark" value="{$list['mark']}">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">截止时间</label>
                <div class="col-sm-8">
                    {php echo tpl_form_field_date('end_time',$list['end_time'],true);}
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">名额</label>
                <div class="col-sm-8">
                    <input type="text" class="form-control"  name="member" value="{$list['member']}">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">参与人数</label>
                <div class="col-sm-8">
                    <input type="text" class="form-control"  name="join_member" value="{$list['join_member']}">
                    <span class="help-block">虚拟人数</span>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">价格</label>
                <div class="col-sm-8">
                    <input type="text" class="form-control"  name="price" value="{$list['price']}">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">最低价格</label>
                <div class="col-sm-8">
                    <input type="text" class="form-control"  name="cut_price" value="{$list['cut_price']}">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">砍价区间</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input type="text" class="form-control" name="min_price" value="{$list['min_price']}">
                        <span class="input-group-btn">
                            <button class="btn btn-default" type="button">至</button>
                        </span>
                        <input type="text" class="form-control" name="max_price" value="{$list['max_price']}">
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">虚拟人数</label>
                <div class="col-sm-8">
                    {if $list['link']}
                    {loop $list['link'] $index $item}
                    <div class="input-group param">
                        <input type="text" name="simg" value="{$item['simg']}" class="form-control" autocomplete="off">
                        <span class="input-group-btn">
                            <button class="btn btn-default" type="button" onclick="showImageDialog(this);">头像</button>
                        </span>
                        <input type="text" name="nick" value="{$item['nick']}" class="form-control" placeholder="昵称" style="width: 33.333%;">
                        <input type="text" name="number" value="{$item['number']}" class="form-control" placeholder="数量" style="width:  33.333%;">
                        <input type="text" name="content" value="{$item['content']}" class="form-control" placeholder="文字" style="width:  33.333%;">
                        <span class="input-group-btn" onclick="parameter.parameter_add(this)">
                            <button class="btn btn-default" type="button"><i class="fa fa-plus"></i></button>
                        </span>
                        <span class="input-group-btn" onclick="parameter.parameter_del(this)">
                            <button class="btn btn-danger" type="button"><i class="fa fa-remove"></i></button>
                        </span>
                    </div>
                    {/loop}
                    {else}
                    <div class="input-group param">
                        <input type="text" name="simg" value="" class="form-control" autocomplete="off">
                        <span class="input-group-btn">
                            <button class="btn btn-default" type="button" onclick="showImageDialog(this);">头像</button>
                        </span>
                        <input type="text" name="nick" value="" class="form-control" placeholder="昵称" style="width: 33.333%;">
                        <input type="text" name="number" value="" class="form-control" placeholder="数量" style="width:  33.333%;">
                        <input type="text" name="content" value="" class="form-control" placeholder="文字" style="width:  33.333%;">
                        <span class="input-group-btn" onclick="parameter.parameter_add(this)">
                            <button class="btn btn-default" type="button"><i class="fa fa-plus"></i></button>
                        </span>
                        <span class="input-group-btn" onclick="parameter.parameter_del(this)">
                            <button class="btn btn-danger" type="button"><i class="fa fa-remove"></i></button>
                        </span>
                    </div>
                    {/if}
                </div>
            </div>
            <script>
                var parameter={
                    parameter_add:function(objc){
                        $(objc).parent().after('<div class="input-group param">' +
                                '<input type="text" name="simg" value="" class="form-control" autocomplete="off">' +
                                '<span class="input-group-btn"> ' +
                                '<button class="btn btn-default" type="button" onclick="showImageDialog(this);">头像</button> ' +
                                '</span> ' +
                                '<input type="text" name="nick" value="" class="form-control" placeholder="昵称" style="width: 33.333%;"> ' +
                                '<input type="text" name="number" value="" class="form-control" placeholder="数量" style="width:  33.333%;"> ' +
                                '<input type="text" name="content" value="" class="form-control" placeholder="文字" style="width:  33.333%;"> ' +
                                '<span class="input-group-btn" onclick="parameter.parameter_add(this)"> ' +
                                '<button class="btn btn-default" type="button"><i class="fa fa-plus"></i></button> ' +
                                '</span> ' +
                                '<span class="input-group-btn" onclick="parameter.parameter_del(this)"> ' +
                                '<button class="btn btn-danger" type="button"><i class="fa fa-remove"></i></button> ' +
                                '</span> ' +
                                '</div>')
                    },
                    parameter_del:function(objc){
                        if($(objc).parent().siblings().length>0){
                            $(objc).parent().remove();
                        }
                    }
                }
            </script>
            <div class="form-group">
                <label class="col-sm-2 control-label">状态</label>
                <div class="col-sm-8">
                    {if $list['status']==1}
                    <input type="checkbox" checked class="js-switch" value="1" name="status">
                    {else}
                    <input type="checkbox" class="js-switch" name="status" value="1">
                    {/if}
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">排序</label>
                <div class="col-sm-8">
                    <input type="text" class="form-control"  name="sort" value="{$list['sort']}">
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-offset-2 col-sm-10">
                    <input type="button" name="submit" class="btn btn-default" value="提交">
                    <a class="btn btn-default" href="{url 'site/entry/'.$_GPC['do'],array('m'=>$_GPC['m'])}">返回</a>
                    <input id="res" name="res" type="reset" style="display:none;" />
                </div>
            </div>
        </form>
    </div>
</div>
<script>
    require(["../addons/{php echo $_GPC['m']}/resource/swal/dist/sweetalert2.min.js","../addons/{php echo $_GPC['m']}/resource/bootstrap-select/bootstrap-select.min.js"],function(){
        $('.selectpicker').selectpicker();
        $(function(){
            $("input[name='submit']").click(function(){
                getJson();
                var data=$(".form-horizontal").serialize();
                $.ajax({
                    type:"post",
                    url:"{url 'site/entry/'.$_GPC['do'],array('m'=>$_GPC['m'],'op'=>'savemodel','version_id'=>$_GPC['version_id'])}",
                    data:data,
                    dataType:'json',
                    success:function(res){
                        if(res.status==1){
                            if($("input[name='id']").val()==""){
                                $("input[name='res']").click();
                                $("body").find(".img-responsive.img-thumbnail").attr("src","");
                                $(".selectpicker").selectpicker('refresh');
                            }
                            swal('操作成功!', '操作成功!', 'success');
                        }else{
                            swal('操作失败!', '操作失败!', 'error');
                        }
                    }
                })
            });
        })
    });

    function getJson(){
        var link=[];
        $("body").find(".param").each(function(){
            var simg=$(this).find("input[name='simg']").val();
            var nick=$(this).find("input[name='nick']").val();
            var number=$(this).find("input[name='number']").val();
            var content=$(this).find("input[name='content']").val();
            if(simg!="" && nick!="" && number!=""){
                var data={simg:simg,nick:nick,number:number,content:content};
                link.push(data);
            }
        });
        if(link.length>0){
            $("input[name='link']").val(JSON.stringify(link));
        }
    }
</script>
{template 'common/footer'}